package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeConfig;
import com.yanqu.road.entity.activity.springdraw.config.SpringDrawConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.apprentice.ApprenticeMgr;
import com.yanqu.road.server.manger.activity.springdraw.SpringDrawMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;

public class ApprenticeRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        List<ActivityInfo> activityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.Apprentice.getValue());
        for (ActivityInfo activityInfo : activityList) {
            if (activityInfo != null) {
                //回收时间
                long recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
                //回收的道具ID
                ApprenticeConfig config = ApprenticeMgr.getConfig(activityInfo.getActivityId());
                if (config != null) {
                    int itemId = config.getAPPRENTICE_ITEM_ID();
                    List<String> paramList = new ArrayList<>();
                    paramList.add(activityInfo.getActivityName());
                    paramList.add(config.getAPPRENTICE_ITEM_USE_REWARD());
                    ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 0, recycleTime, paramList);
                }
            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.Apprentice.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int itemId = data.getItemId();
        //获取背包道具
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        //使用掉
        if (userBagItem != null && userBagItem.getNum() > 0) {
            String activityName = data.getParamList().get(0);
            String weightReward = data.getParamList().get(1);
            Property reward = new Property();
            for (int i = 0; i < userBagItem.getNum(); i++) {
                Property onceReward = PropertyHelper.parseNewStringToProperty(weightReward);
                reward.addProperty(onceReward);
            }
            //删除道具，并发放奖励
            this.removeItemAndSendReward(userId, userBagItem, activityName, reward);
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
